package com.zzw.java.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzw.java.service.LevelResultService;
import com.zzw.java.dao.LevelResultMapper;
import com.zzw.java.entity.LevelResult;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @Author：hcy
 * @Package：com.zzw.java.Service.impl
 * @version：1.0
 * @Date：2025/8/19 14:32
 */


@Service
public class LevelResultServiceImpl extends ServiceImpl<LevelResultMapper, LevelResult> implements LevelResultService {


    /**
     * 定时删除已上传的历史数据（每天23:00:00执行，删除5天前数据）
     */
    @Scheduled(cron = "0 0 23 * * ?")
    public void scheduledDel() {
        LocalDateTime fiveDaysAgo = LocalDateTime.now().minusDays(5);
        LambdaQueryWrapper<LevelResult> lambdaQueryWrapper = new LambdaQueryWrapper<LevelResult>()
                .eq(LevelResult::getUploadStatus, 1)
                .lt(LevelResult::getSurveyTime, fiveDaysAgo);
        this.remove(lambdaQueryWrapper);
    }
}
